/*
 * ModelLoaderObject.cpp
 *
 *  Created on: 03.10.2012
 *      Author: caffeine
 */

#include "ModelLoaderObject.h"
#include <log/Log.h>

namespace irr{
namespace object{

ModelLoaderObject::ModelLoaderObject(ModelObject*mo,bool sl) {
	modelObject=mo;
	if (modelObject)
		modelObject->grab();
	sync_load=sl;
}

ModelLoaderObject::~ModelLoaderObject() {
	if (modelObject){
		modelObject->drop();
	}
}

bool ModelLoaderObject::isModelLoaded(){
	if (!modelObject)
		return false;
	return modelObject->isLoaded();
}

ModelObject*ModelLoaderObject::getModel(){
	return modelObject;
}

void ModelLoaderObject::giveModel(ModelObject*model){
	setModel(model);
	if (model)
		model->drop();
}

void ModelLoaderObject::setModel(ModelObject*model){
	if (modelObject==model)
		return;
	if (modelObject)
		modelObject->drop();
	modelObject=model;
	if (modelObject)
		modelObject->grab();
}

void ModelLoaderObject::loadModel(){
	MARKER;
	if (!modelObject)
		return;
	MARKER;
	if (sync_load)
		modelObject->load();
	else
		modelObject->load_unsync();
	MARKER;
}

void ModelLoaderObject::unloadModel(){
	MARKER;
	if (!modelObject)
		return;
	MARKER;
	if (sync_load){
		MARKER;
		getModel()->unload();
		MARKER;
	}else{
		MARKER;
		getModel()->unload_unsync();
		MARKER;
	}
	MARKER;
}

}//namespace object
}//namespace irr
